<template>
  <k-select-http
    v-model="val"
    paramsKey="searchValue"
    :immediately="true"
    :httpfn="getWarehouseList"
    :keyprops="{ label: 'name', value: 'warehouseId' }"
    @change="onChange"
  />
</template>

<script setup lang="ts">
import { ref, watch } from "vue";
import kSelectHttp from "@/components/k-select-http/index.vue";
import { allListApi as getWarehouseList } from "@/api/warehouse";

const props = defineProps({
  modelValue: {
    type: [Array, String, Number],
    default: ""
  }
});
/* 双向绑定 */
const val: any = ref("");
const emit = defineEmits(["update:modelValue", "change"]);
const onChange = (val, item) => {
  emit("update:modelValue", val);
  emit("change", val, item);
};

watch(
  () => props.modelValue,
  (newVal, oldVal) => {
    val.value = newVal;
  }
);
</script>
